package com.example.tvidemo.service;

import com.example.tvidemo.entity.Role;
import com.example.tvidemo.mapper.RoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class RoleService {

    @Autowired
    private RoleMapper roleMapper;

    public List<Role> findAll(){
       return roleMapper.findAll();
    }

    public Role findById(String id){
        return roleMapper.findById(id);
    }

    public void addRole(Role role){
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        role.setId(uuid);
        roleMapper.addRole(role);
    }

    public void updateRole(Role role){
        roleMapper.updateRole(role);
    }

    public void deleteRole(String id){
        roleMapper.deleteRole(id);
    }

    public void authorizeRole(String userId,String roleId){
        roleMapper.authorizeRole(userId,roleId);
    }

}
